public class Demo5 {
    static boolean flag = false;
    public static void main(String[] args) {
        Object object = new Object();
        Thread t1 = new Thread(()->{
            synchronized ( object){
                System.out.println("t1 wait 之前");
                while (!flag){
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("t1 wait 之后");
            }
        });
        Thread t2 = new Thread(()->{
            synchronized ( object){
                System.out.println("t2 wait 之前");
                while(!flag){
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("t2 wait 之后");
            }
        });
        Thread t3 = new Thread(()->{
            synchronized ( object){
                System.out.println("t3 wait 之前");
                object.notify();
                flag = true;
                System.out.println("t3 wait 之后");
            }
        });
        t2.start();
        t1.start();
        t3.start();

    }
}
